<?php
declare (strict_types=1);

namespace app\api\controller;

use app\api\model\TopicList;
use app\BaseController;
use app\tool\controller\ArrController;
use app\tool\controller\SendController;
use app\tool\controller\UploadController;
use think\Request;

class TopicListController extends BaseController
{
    public function getDataFromUrl()
    {
        /*$responseArray = SendController::strArr();
        $getData = $responseArray['data']['topicList'];
        TopicList::insertALL($getData);
        $this->P($getData);*/
    }

    /*
     * 更改首页数据
     * */
    public function changList()
    {
        $list = TopicList::order('id asc')->limit(10)->select()->toArray();
        return json_encode(['data' => $list]);
        /*$list = TopicList::select()->toArray();
        foreach ($list as $key => $value) {
            $imgUrl = $value['bgImgUrl'];
            $uploadImg = UploadController::upload('', 'ad', $imgUrl);
            $updata = ['bgImgUrl' => $uploadImg['img'], 'coverImgUrl' => $uploadImg['img'], 'direction' => str_replace($imgUrl, $uploadImg['img'], $value['direction'])];
            TopicList::where('id', $value['id'])->update($updata);
        }*/
    }

    /*获取答案*/
    public function getTopicLoad()
    {
        $list = TopicList::select()->toArray();
        $url = 'https://quce.51he.cn/api/Test_Topic/TopicLoad';
        foreach ($list as $key => $value) {
            $params = ['ID' => $value['id']];
            $res = SendController::sendPost($url, $params);
            $this->P($res);
        }
    }

    public function checkData()
    {
        /*   $arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6];
           $str = '这个世界真实非sdf常的奇妙啊';
           $this->P(ArrController::inversion($str));*/
        /*   $array = [
               ['id' => 1, 'name' => 'Alice'],
               ['id' => 2, 'name' => 'Bob'],
               ['id' => 1, 'name' => 'Charlie'],
               ['id' => 3, 'name' => 'David']
           ];
           $find = ArrController::findByKey($array, 'id', 1);
           $this->P($find);*/
        $str = '今天天机dsaf你说哈哈哈';
        $from = '天';
        $to = '地';
        $newStr = ArrController::changeStr($from, $to, $str);
        $this->P($newStr);
    }
}
